package com.yipei.business.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.text.StrBuilder;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.yipei.business.domain.MlKLineMaster;
import com.yipei.business.domain.MlSymbolsInfo;
import com.yipei.business.service.IMlKLineMasterService;
import com.yipei.business.service.IMlSymbolsInfoService;
import com.yipei.business.vo.*;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.StringUtils;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 行情Controller
 *
 * @author yipei
 * @date 2024-12-20
 */
@Api(tags = "股票，基金，债券数据接口", description = "股票，基金，债券数据接口")
@RestController
@RequestMapping("/business/mlkline")
public class MlKLineMasterController extends BaseController {
    @Autowired
    private IMlKLineMasterService mlKLineMasterService;

    /**
     * 查询行情列表
     */
    @ApiOperation("涨跌幅数据分布")
    //@PreAuthorize("@ss.hasPermi('business:mlkline:list')")
    @GetMapping("/list")
    public AjaxResult list(MlKLineMasterVo mlKLineMasterVo) throws IOException, InterruptedException {
        // 1. 获取所有沪深A股代码
        List<String> codes = new ArrayList<>();
        codes.addAll(fetchAllStockCodes());
        List<MlKLineMasterVo> mlKLineMasters = mlKLineMasterService.getAguMklines(codes);
        return AjaxResult.success(mlKLineMasters);
    }

    @ApiOperation("K线先锋数据")
    @GetMapping("/list2")
    public TableDataInfo list2(MlKLineMaster mlKLineMaster) {
        startPage();
        List<MlKLineMaster> list = mlKLineMasterService.selectMlKLineMasterList(mlKLineMaster);
        return getDataTable(list);
    }

    @ApiOperation("涨跌幅数据分布/riseCount：涨，drawCount：平，fallCount：跌")
    @GetMapping("/chg")
    public AjaxResult chg(UpDownVo upDownVo) throws IOException, InterruptedException {
        // 1. 获取所有沪深A股代码
        List<String> codes = new ArrayList<>();
        codes.addAll(fetchAllStockCodes());
        // 2. 分批拉取并打印实时行情
        List<BigDecimal> fetchAndPrintBatchQuotes = fetchAndPrintBatchQuotes(codes);
        upDownVo.setRiseCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(BigDecimal.ZERO) > 0).count()));
        upDownVo.setFallCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(BigDecimal.ZERO) < 0).count()));
        upDownVo.setDrawCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(BigDecimal.ZERO) == 0).count()));
        upDownVo.setLimitUpCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(new BigDecimal(7)) >= 0).count()));
        upDownVo.setFiveSevenCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(new BigDecimal(7)) < 0 && e.compareTo(new BigDecimal(5)) >= 0).count()));
        upDownVo.setThreeFiveCount(BigDecimal.valueOf((fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(new BigDecimal(5)) < 0 && e.compareTo(new BigDecimal(3)) >= 0).count())));
        upDownVo.setZeroTherrCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(new BigDecimal(3)) < 0 && e.compareTo(new BigDecimal(0)) > 0).count()));
        upDownVo.setBurdenFiveSevenCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(new BigDecimal(-5)) <= 0 && e.compareTo(new BigDecimal(-7)) > 0).count()));
        upDownVo.setBurdenThreeFiveCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(new BigDecimal(-3)) <= 0 && e.compareTo(new BigDecimal(-5)) > 0).count()));
        upDownVo.setBurdenZeroTherrCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(new BigDecimal(0)) < 0 && e.compareTo(new BigDecimal(-3)) > 0).count()));
        upDownVo.setLimitDownCount(BigDecimal.valueOf(fetchAndPrintBatchQuotes.stream().filter(e -> e.compareTo(new BigDecimal(-7)) <= 0).count()));
        return AjaxResult.success(upDownVo);
    }

    private List<BigDecimal> fetchAndPrintBatchQuotes(List<String> codes) throws IOException, InterruptedException {
        int batchSize = 200; // 腾讯接口建议每批200只以内
        List<BigDecimal> percentList = new ArrayList<>();
        for (int i = 0; i < codes.size(); i += batchSize) {
            List<String> batch = codes.subList(i, Math.min(i + batchSize, codes.size()));
            String query = URLEncoder.encode(String.join(",", batch), "UTF-8");
            String url = "https://sqt.gtimg.cn/?q=" + query + "&fmt=json&app=wstock&t=" + System.currentTimeMillis();
            HttpClient client = HttpClients.createDefault();
            HttpGet request = new HttpGet(url); //示例URL，请替换为实际的股票代码
            request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
            HttpResponse response = client.execute(request);
            if (response.getStatusLine().getStatusCode() == 200) {
                HttpEntity entity = response.getEntity();
                String json = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
                Gson gson = new Gson();
                JsonObject obj = gson.fromJson(json, JsonObject.class);
                for (String code : obj.keySet()) {
                    JsonArray arr = obj.getAsJsonArray(code);
                    // 防御越界
                    if (arr.size() > 32) {
                        percentList.add(arr.get(32).getAsBigDecimal());
                    } else {
                        percentList.add(BigDecimal.ZERO); // 或null，或跳过
                    }
                }
                // 防止频繁请求被风控
                Thread.sleep(600);
            }
        }
        return percentList;
    }

    private Map<String, Map<String, Object>> parseSimpleJson(String json) {
        Map<String, Map<String, Object>> result = new LinkedHashMap<>();
        try {
            // 去掉最外层大括号
            String body = json.substring(1, json.length() - 1);
            String[] entries = body.split("\"\\s*,\\s*\"");
            for (String entry : entries) {
                // 分割key和value
                int idx = entry.indexOf("\":");
                if (idx < 0) continue;
                String key = entry.substring(0, idx).replaceAll("^\"|\"$", "");
                String obj = entry.substring(idx + 2).trim();
                if (obj.startsWith("{")) {
                    Map<String, Object> inner = new LinkedHashMap<>();
                    // 解析字段
                    String[] fields = obj.substring(1, obj.length() - 1).split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
                    for (String field : fields) {
                        int idx2 = field.indexOf(':');
                        if (idx2 > 0) {
                            String fkey = field.substring(0, idx2).replaceAll("^\"|\"$", "");
                            String fval = field.substring(idx2 + 1).replaceAll("^\"|\"$", "");
                            inner.put(fkey, fval);
                        }
                    }
                    result.put(key, inner);
                }
            }
        } catch (Exception e) {
            // 简单解析，失败跳过
        }
        return result;
    }

    @Autowired
    private IMlSymbolsInfoService mlSymbolsInfoService;

    private Collection<String> fetchAllStockCodes() {
        List<String> codes = new ArrayList<>();
        List<MlSymbolsInfo> list = mlSymbolsInfoService.lambdaQuery().select().list();
        List<String> symbol = list.stream().map(MlSymbolsInfo::getSymbol).collect(Collectors.toList());
        for (String code : symbol) {
            if (code.startsWith("60") || code.startsWith("68") || code.startsWith("688") || code.startsWith("689")) {
                codes.add(("sh" + code).toLowerCase());
            } else if (code.startsWith("00") || code.startsWith("30") || code.startsWith("002") || code.startsWith("003")) {
                codes.add(("sz" + code).toLowerCase());
            } else if (code.startsWith("4") || code.startsWith("8") || code.startsWith("43") || code.startsWith("83") || code.startsWith("87")) {
                codes.add(("bj" + code).toLowerCase());
            }
        }
        return codes;
    }

    //@PreAuthorize("@ss.hasPermi('business:mlkline:list')")
    @GetMapping("/hostList")
    @ApiOperation("热度最高1-9；共鸣度最高10-20")
    public AjaxResult hostList(HostGuVo hostGuVo) throws IOException {
        SimpleDateFormat dateStr = new SimpleDateFormat("yyyyMMdd");
        String format = dateStr.format(new Date());
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://push2ex.eastmoney.com/getTopicQSPool?cb=callbackdata&ut=7eea3edcaed734bea9cbfc24409ed989&dpt=wz.ztzt&Pageindex=0&pagesize=20&sort=zdp%3Adesc&date=" + format); //示例URL，请替换为实际的股票代码
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        List<HostGuVo> hostGuVos = new ArrayList<>();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("callbackdata", "");
            result = Stream.of(result.split(";")).collect(Collectors.joining(";"));
            result = result.substring(1, result.length() - 1);
            JSONObject jsonObject = JSONObject.parseObject(result).getJSONObject("data");
            JSONArray diff = jsonObject.getJSONArray("pool");
            hostGuVos = diff.toJavaList(HostGuVo.class);
        }
        for (HostGuVo guVo : hostGuVos) {
            guVo.setName(guVo.getN());
            guVo.setSymbol(guVo.getC());
        }
        return AjaxResult.success(hostGuVos);
    }

    /**
     * 导出行情列表
     */
    //@PreAuthorize("@ss.hasPermi('business:mlkline:export')")
    @Log(title = "行情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlKLineMaster mlKLineMaster) {
        List<MlKLineMaster> list = mlKLineMasterService.selectMlKLineMasterList(mlKLineMaster);
        ExcelUtil<MlKLineMaster> util = new ExcelUtil<MlKLineMaster>(MlKLineMaster.class);
        util.exportExcel(response, list, "行情数据");
    }

    /**
     * 获取行情详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:mlkline:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlKLineMasterService.selectMlKLineMasterById(id));
    }

    /**
     * 新增行情
     */
    //@PreAuthorize("@ss.hasPermi('business:mlkline:add')")
    @Log(title = "行情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlKLineMaster mlKLineMaster) {
        return toAjax(mlKLineMasterService.insertMlKLineMaster(mlKLineMaster));
    }

    /**
     * 修改行情
     */
    //@PreAuthorize("@ss.hasPermi('business:mlkline:edit')")
    @Log(title = "行情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlKLineMaster mlKLineMaster) {
        return toAjax(mlKLineMasterService.updateMlKLineMaster(mlKLineMaster));
    }

    /**
     * 删除行情
     */
    //@PreAuthorize("@ss.hasPermi('business:mlkline:remove')")
    @Log(title = "行情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlKLineMasterService.deleteMlKLineMasterByIds(ids));
    }

    @ApiOperation("A股沪深京数据")
    @GetMapping("/indexData")
    public AjaxResult indexData(MlKLineMasterVo mlKLineMasterVo) throws IOException, InterruptedException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://sqt.gtimg.cn/q=sh000001,sz399001,sz399006,sh000300,sh000688&fmt=json&app=wstock" + System.currentTimeMillis()); //示例URL，请替换为实际的股票代码
        List<MlKLineMasterVo> mlKLineMasterVos = mlKLineMasterService.getIndexData(client, request);
        return AjaxResult.success(mlKLineMasterVos);
    }

    private List<MlKLineMasterVo> getAjaxResult(HttpClient client, HttpGet request) throws IOException {
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        List<MlKLineMasterVo> mlKLineMasters = new ArrayList<>();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            result = Stream.of(result.split(";")).collect(Collectors.joining(";"));
            result = result.substring(1, result.length() - 1);
            JSONObject jsonObject = JSONObject.parseObject(result).getJSONObject("data");
            JSONArray diff = jsonObject.getJSONArray("diff");
            mlKLineMasters = diff.toJavaList(MlKLineMasterVo.class);
        }
        for (MlKLineMasterVo mlKLineMaster : mlKLineMasters) {
            mlKLineMaster.setF2(String.valueOf(new BigDecimal(mlKLineMaster.getF2()).divide(BigDecimal.valueOf(100))));
            mlKLineMaster.setF3(new BigDecimal(mlKLineMaster.getF3()).divide(BigDecimal.valueOf(100)) + "%");
            mlKLineMaster.setF4(new BigDecimal(mlKLineMaster.getF4()).divide(BigDecimal.valueOf(100)) + "%");
            mlKLineMaster.setF15(String.valueOf(new BigDecimal(mlKLineMaster.getF15()).divide(BigDecimal.valueOf(100))));
            mlKLineMaster.setF16(String.valueOf(new BigDecimal(mlKLineMaster.getF16()).divide(BigDecimal.valueOf(100))));
            mlKLineMaster.setF17(String.valueOf(new BigDecimal(mlKLineMaster.getF17()).divide(BigDecimal.valueOf(100))));
            mlKLineMaster.setF18(String.valueOf(new BigDecimal(mlKLineMaster.getF18()).divide(BigDecimal.valueOf(100))));
            mlKLineMaster.setF7(new BigDecimal(mlKLineMaster.getF7()).divide(BigDecimal.valueOf(100)) + "%");
            mlKLineMaster.setF8(new BigDecimal(mlKLineMaster.getF8()).divide(BigDecimal.valueOf(100)) + "%");
        }
        return mlKLineMasters;
    }

    @ApiOperation("A股科创板")
    @GetMapping("/keChuangData")
    public AjaxResult keChuangData(MlKLineMasterVo mlKLineMasterVo) throws IOException, InterruptedException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://sqt.gtimg.cn/q=sh000688,sh000682,sh000683,sh000685,sh000687,sh000689&fmt=json&app=wstock" + System.currentTimeMillis()); //示例URL，请替换为实际的股票代码
        List<MlKLineMasterVo> ajaxResult = mlKLineMasterService.getKeChuangData(client, request);
        return AjaxResult.success(ajaxResult);
    }

    @ApiOperation("A股创业板数据")
    @GetMapping("/chuangYeBan")
    public AjaxResult chuangYeBan(MlKLineMasterVo mlKLineMasterVo) throws IOException, InterruptedException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://sqt.gtimg.cn/q=sz399006,sz399673,sz399012,sz399293,sz399102&fmt=json&app=wstock" + System.currentTimeMillis()); //示例URL，请替换为实际的股票代码
        List<MlKLineMasterVo> ajaxResult = mlKLineMasterService.getChuangYeBan(client, request);
        return AjaxResult.success(ajaxResult);
    }

    @ApiOperation("基金数据")
    @GetMapping("/jiJin")
    public AjaxResult jiJin(MlKLineMasterVo mlKLineMasterVo) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://push2.eastmoney.com/api/qt/ulist.np/get?ut=6d2ffaa6a585d612eda28417681d58fb&secids=1.000011,0.399103,0.399306,0.399300&cb=jQuery"); //示例URL，请替换为实际的股票代码
        List<MlKLineMasterVo> ajaxResult = getAjaxResult(client, request);
        return AjaxResult.success(ajaxResult);
    }

    @ApiOperation("债券指数")
    @GetMapping("/zhaiQuan")
    public AjaxResult zhaiQuandata(MlKLineMasterVo mlKLineMasterVo) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://push2.eastmoney.com/api/qt/ulist.np/get?ut=6d2ffaa6a585d612eda28417681d58fb&secids=1.000011,0.399103,0.399306,0.399300&cb=jQuery"); //示例URL，请替换为实际的股票代码
        List<MlKLineMasterVo> ajaxResult = getAjaxResult(client, request);
        return AjaxResult.success(ajaxResult);
    }


    @ApiOperation("a股涨跌排行榜数据")
    @GetMapping("/aGuUpDown")
    public AjaxResult aGuUpDown(AGuUpDownVo aGuUpDownVo) throws IOException {
        /**
         *  创业板涨幅
         */
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=20&sort=changepercent&asc=0&node=cyb"); //示例URL，请替换为实际的股票代码
        HttpResponse response = client.execute(request);
        aGuUpDownVo.setCyb_up(mlKLineMasters(request, response));
        /**
         * 创业板跌幅
         *
         */
        HttpGet request2 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=20&sort=changepercent&asc=1&node=cyb"); //示例URL，请替换为实际的股票代码
        HttpResponse response2 = client.execute(request2);
        aGuUpDownVo.setCyb_down(mlKLineMasters(request2, response2));
        /**
         * 沪深京涨幅
         */
        HttpGet request3 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=30&sort=changepercent&asc=0&node=hs_a"); //示例URL，请替换为实际的股票代码
        HttpResponse response3 = client.execute(request3);
        aGuUpDownVo.setHsj_up(mlKLineMasters(request3, response3));
        /**
         * 沪深京跌幅
         */
        HttpGet request4 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=30&sort=changepercent&asc=1&node=hs_a"); //示例URL，请替换为实际的股票代码
        HttpResponse response4 = client.execute(request4);
        aGuUpDownVo.setHsj_down(mlKLineMasters(request4, response4));

        /**
         * 科创板涨幅
         */
        HttpGet request5 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=20&sort=changepercent&asc=0&node=kcb"); //示例URL，请替换为实际的股票代码
        HttpResponse response5 = client.execute(request5);
        aGuUpDownVo.setKcb_up(mlKLineMasters(request5, response5));

        /**
         * 科创板跌幅
         */
        HttpGet request6 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=20&sort=changepercent&asc=1&node=kcb"); //示例URL，请替换为实际的股票代码
        HttpResponse response6 = client.execute(request6);
        aGuUpDownVo.setKcb_down(mlKLineMasters(request6, response6));

        return AjaxResult.success(aGuUpDownVo);


        //创业板涨幅
        //  https://49.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=15&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:1+t:23
        //创业板跌幅
        // https://49.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=10&po=0&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:80
        //沪深京涨幅
        // https://49.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=15&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152&_=1736480150837

        //沪深京跌幅
        //https://22.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=15&po=0&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048
        //科创办涨幅
        // https://22.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=15&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:1+t:23
        //可创办跌幅
        // https://22.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=15&po=0&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:1+t:23
    }

    private List<MlKLineMasterVo> mlKLineMasters(HttpGet request, HttpResponse response) throws IOException {
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        List<SymbolVo> symbolVos = new ArrayList<>();
        List<MlKLineMasterVo> mlKLineMasters = new ArrayList<>();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8");
            JSONArray jsonArray = JSONArray.parseArray(result);
            symbolVos = jsonArray.toJavaList(SymbolVo.class);
            for (SymbolVo symbolVo : symbolVos) {
                MlKLineMasterVo mlKLineMasterVo = new MlKLineMasterVo();
                mlKLineMasterVo.setF12(symbolVo.getCode());
                mlKLineMasterVo.setF14(symbolVo.getName());
                mlKLineMasterVo.setF2(symbolVo.getTrade());
                mlKLineMasterVo.setF3(symbolVo.getChangepercent());
                mlKLineMasterVo.setF4(symbolVo.getPricechange());
                mlKLineMasterVo.setF6(symbolVo.getAmount());
                mlKLineMasterVo.setF15(symbolVo.getHigh());
                mlKLineMasterVo.setF16(symbolVo.getLow());
                mlKLineMasterVo.setF17(symbolVo.getOpen());
                mlKLineMasterVo.setF18(symbolVo.getSettlement());
                mlKLineMasterVo.setF7(symbolVo.getTurnoverratio());
                mlKLineMasterVo.setF9(symbolVo.getPer());
                mlKLineMasterVo.setF20(symbolVo.getMktcap());
                mlKLineMasters.add(mlKLineMasterVo);
            }

        }
        return mlKLineMasters;
    }

    private List<MlKLineMasterVo> mlKLineMastersData(HttpGet request, HttpResponse response) throws IOException {
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        List<MlKLineMasterVo> mlKLineMasters = new ArrayList<>();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            result = Stream.of(result.split(";")).collect(Collectors.joining(";"));
            result = result.substring(1, result.length() - 1);
            JSONObject jsonObject = JSONObject.parseObject(result).getJSONObject("data");
            JSONArray diff = jsonObject.getJSONArray("diff");
            mlKLineMasters = diff.toJavaList(MlKLineMasterVo.class);
        }
        return mlKLineMasters;
    }

    //基金排行数据
    //https://8.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=3000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&fid=f3&fs=b:MK0021,b:MK0022,b:MK0023,b:MK0024,b:MK0827,b:MK0404,b:MK0405,b:MK0406,b:MK0407
    @ApiOperation("基金排行数据")
    @GetMapping("/jiJInPaiHang")
    public AjaxResult jiJInPaiHang(MlKLineMasterVo mlKLineMasterVo) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://8.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=3000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&fid=f3&fs=b:MK0021,b:MK0022,b:MK0023,b:MK0024,b:MK0827,b:MK0404,b:MK0405,b:MK0406,b:MK0407"); //示例URL，请替换为实际的股票代码
        HttpResponse response = client.execute(request);
        List<MlKLineMasterVo> mlKLineMasterVos = mlKLineMastersData(request, response);
        return AjaxResult.success(mlKLineMasterVos);
    }

    //https://56.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=1000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&fid=f230&fs=b:MK0354
    @ApiOperation("债券排行数据")
    @GetMapping("/zhaiQuanPaiHang")
    public AjaxResult zhaiQuan(MlKLineMasterVo mlKLineMasterVo) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://56.push2.eastmoney.com/api/qt/clist/get?cb=jQuery&pn=1&pz=1000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&fid=f230&fs=b:MK0354"); //示例URL，请替换为实际的股票代码
        HttpResponse response = client.execute(request);
        List<MlKLineMasterVo> mlKLineMasterVos = mlKLineMastersData(request, response);
        return AjaxResult.success(mlKLineMasterVos);
    }

    //成交明细
    //https://push2.eastmoney.com/api/qt/stock/details/get?fields1=f1,f2,f3,f4&fields2=f51,f52,f53,f54,f55&fltt=2&cb=jQuery&pos=-500&secid=0.300412&ut=fa5fd1943c7b386f172d6893dbfba10b
    @ApiOperation("今日交易数据")
    @GetMapping("/todayDaea")
    public AjaxResult TodayDaea(@RequestParam(name = "f12", required = true) String f12, @RequestParam(name = "f14") String f14) throws IOException, InterruptedException {
        List<TodayDaealVo> recentTicks;
        String symbol1 = "sh" + f12;
        recentTicks = mlKLineMasterService.fetchLatestTicks(symbol1, 4000);
        if (CollectionUtils.isEmpty(recentTicks)) {
            String symbol2 = "sz" + f12;
            recentTicks = mlKLineMasterService.fetchLatestTicks(symbol2, 4000);
        } else if (CollectionUtils.isEmpty(recentTicks)) {
            String symbol3 = "bj" + f12;
            recentTicks = mlKLineMasterService.fetchLatestTicks(symbol3, 4000);
        }
        return AjaxResult.success(recentTicks);
    }

    /**
     * 获得行情头具体数据
     *
     * @param
     * @return
     * @throws IOException
     */
    @ApiOperation("获得行情头具体数据/昨收，今开，总量这些")
    @GetMapping("/getSymbolInfo")
    public AjaxResult getSymbolInfo(@RequestParam(name = "f12", required = true) String f12, @RequestParam(name = "f14", required = true) String f14) throws IOException, InterruptedException {
        List<MlKLineMasterVo> ajaxResult = mlKLineMasterService.getSymbolInfo(f12, f14);
        List<MlKLineMasterVo> mlKLineMasterVos = ajaxResult.stream().filter(e -> e.getF14().equals(f14)).collect(Collectors.toList());
        return AjaxResult.success(mlKLineMasterVos);
    }

    @ApiOperation("分时数据交易数据")
    @GetMapping("/minuteData")
    public AjaxResult minute(@RequestParam(name = "f12", required = true) String f12, @RequestParam(name = "f14", required = true) String f14) throws IOException {
        String secid = null;
        String code = f12; // 替换为你需要的股票代码
        String marketType = getAStockMarket(code);
        if (marketType.equals("沪市A股")) {
            secid = "1." + code;
        } else if (marketType.equals("深市A股")) {
            secid = "0." + code;
        } else {
            secid = "0." + code;
        }
        Date now = new Date();
        // 定义日期格式
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        // 格式化
        String formattedDate = sdf1.format(now);
//        List<Object> resultList = new ArrayList<>();
        MinuteDataVo minuteDataVo = new MinuteDataVo();
        List<Object> data1 = minuteDataVo.getData();
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=" + secid + "&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=1&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject json = JSON.parseObject(result);
            JSONObject data = json.getJSONObject("data");
            JSONArray klines = data.getJSONArray("klines");
            // 1分钟K线的时间格式通常为 "yyyy-MM-dd HH:mm"
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
            for (int i = 0; i < klines.size(); i++) {
                String k = klines.getString(i);
                String[] arr = k.split(",");
                Object[] row = new Object[arr.length + 1];

                // 处理时间戳
                String dateStr = arr[0]; // 例如 "2025-06-09 09:40"
                long ts = 0;
                try {
                    Date date = sdf.parse(dateStr);
                    ts = date.getTime() / 1000; // 秒级时间戳
                } catch (Exception e) {
                    // 如果格式是"yyyy-MM-dd"，可以用另一个格式处理
                    try {
                        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
                        sdf2.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
                        Date date = sdf2.parse(dateStr);
                        ts = date.getTime() / 1000;
                    } catch (Exception ex) {
                        ts = 0;
                    }
                }

                row[0] = ts;
                row[1] = dateStr;
                // 其余字段转数字
                for (int j = 1; j < arr.length; j++) {
                    try {
                        if (arr[j].contains(".")) {
                            row[j + 1] = Double.parseDouble(arr[j]);
                        } else {
                            row[j + 1] = Integer.parseInt(arr[j]);
                        }
                    } catch (Exception e) {
                        row[j + 1] = arr[j];
                    }
                }
                data1.add(row); // 添加到结果集中
            }
        }
        return AjaxResult.success(minuteDataVo);
    }

    // 判断是否为沪深A股
    public static String getAStockMarket(String code) {
        if (code == null || code.length() != 6) return "未知";
        if (code.startsWith("6")) return "沪市A股";
        if (code.startsWith("0") || code.startsWith("3") || code.startsWith("2")) return "深市A股";
        return "非A股";
    }

    // 由东方财富secid判断市场
    public static String getMarketBySecid(String secid) {
        if (secid.startsWith("1.")) return "沪市";
        if (secid.startsWith("0.")) return "深市";
        return "未知";
    }
    //资讯
    //https://finance.pae.baidu.com/vapi/sentimentlist?market=ab&code=300307&query=300307&financeType=stock&benefitType=&pn=0&rn=10&finClientType=pc

    //新闻
    //https://finance.pae.baidu.com/vapi/sentimentlist?market=ab&code=300307&query=300307&financeType=stock&benefitType=&pn=0&rn=10&finClientType=pc

    @ApiOperation("个股新闻")
    @GetMapping("/news")
    public AjaxResult news(@RequestParam(name = "f12", required = true) String f12, @RequestParam(name = "f14", required = true) String f14) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://finance.pae.baidu.com/vapi/sentimentlist?market=ab&code=" + f12 + "&query=" + f12 + "&financeType=stock&benefitType=&pn=0&rn=20&finClientType=pc"); //示例URL，请替换为实际的股票代码
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        List<NewVo> newVos = new ArrayList<>();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
//            result = Stream.of(result.split(";")).collect(Collectors.joining(";"));
//            result = result.substring(1, result.length() - 1);
            JSONArray result1 = JSONObject.parseObject(result).getJSONArray("Result");
            JSONObject jsonObject = new JSONObject();
            for (int i = 0; i < result1.size(); i++) {
                // 获取JSONArray中的元素
                String name = result1.getString(i);
                // 将元素添加到JSONObject中，使用索引作为键
                jsonObject.put("name" + i, name);
            }
            JSONObject tplData = jsonObject.getJSONObject("name0").getJSONObject("TplData");
            JSONArray nesArrays = tplData.getJSONObject("aiSentimentXcxListInfo").getJSONArray("sentimentListInfo");

            newVos = nesArrays.toJavaList(NewVo.class);
        }
        return AjaxResult.success(newVos);
    }

    @ApiOperation("个股快讯")
    @GetMapping("/newsFlash")
    public AjaxResult newsFlash(@RequestParam(name = "f12", required = true) String f12, @RequestParam(name = "f14", required = true) String f14) throws IOException {
        HttpClient client = HttpClients.createDefault();
//        HttpGet request = new HttpGet("https://finance.pae.baidu.com/vapi/sentimentlist?market=ab&code=" + f12 + "&query=" + f12 + "&financeType=stock&benefitType=&pn=0&rn=20&finClientType=pc"); //示例URL，请替换为实际的股票代码
        HttpGet request = new HttpGet("https://finance.pae.baidu.com/selfselect/expressnews?rn=20&pn=0&financeType=stock&code=" + f12 + "&finClientType=pc"); //示例URL，请替换为实际的股票代码
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        List<NewVo> newVos = new ArrayList<>();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject result1 = JSONObject.parseObject(result).getJSONObject("Result");
            JSONArray jsonArray = result1.getJSONObject("content").getJSONArray("list");
            newVos = jsonArray.toJavaList(NewVo.class);
        }
        for (NewVo newVo : newVos) {
            BigDecimal publishTime = new BigDecimal(newVo.getPublish_time());
            String subtract = String.valueOf(publishTime.multiply(BigDecimal.valueOf(1000L)));
            JSONObject jsonObject = JSONObject.parseObject(newVo.getContent());
            JSONArray items = jsonObject.getJSONArray("items");
            List<NewsItems> newsItems = items.toJavaList(NewsItems.class);
            for (NewsItems newsItem : newsItems) {
                newVo.setTitle(newsItem.getData());
            }
            DateTime dateTime = new DateTime(subtract);
            String formattedDateTime = dateTime.toString("yyyy-MM-dd HH:mm:ss");

            newVo.setApiBak(newVo.getThird_url());
            newVo.setPublishTime(formattedDateTime);
        }
        return AjaxResult.success(newVos);
    }

    @ApiOperation("个股分析")
    @GetMapping("/analysis")
    public AjaxResult analysis(@RequestParam(name = "f12", required = true) String f12, @RequestParam(name = "f14", required = true) String f14) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://finance.pae.baidu.com/vapi/v1/analysis?code=" + f12 + "&market=ab&isNew=1&finClientType=pc"); //示例URL，请替换为实际的股票代码
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        AnalysisVo analysisVo = new AnalysisVo();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject result1 = JSONObject.parseObject(result).getJSONObject("Result");
            JSONObject synthesisScore = result1.getJSONObject("synthesisScore");
            analysisVo = synthesisScore.toJavaObject(AnalysisVo.class);
        }
        if (ObjectUtils.isEmpty(analysisVo)) {
            return AjaxResult.success("未获取到分析数据");
        } else {
            return AjaxResult.success(analysisVo);
        }
    }

    //
    @ApiOperation("个股财务")
    @GetMapping("/finance")
    public AjaxResult finance(@RequestParam(name = "f12", required = true) String f12) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://finance.pae.baidu.com/api/stockwidget?code=" + f12 + "&market=ab&type=stock&widgetType=finance&finClientType=pc"); //示例URL，请替换为实际的股票代码
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        List<FinanceVo> financeVos = new ArrayList<>();
        HttpResponse response = client.execute(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject result1 = JSONObject.parseObject(result).getJSONObject("Result");
            JSONObject content = result1.getJSONObject("content");
            JSONArray jsonArray = content.getJSONObject("balanceSheet").getJSONArray("chartInfo");
            List<ChartInfoVo> chartInfoVos = jsonArray.toJavaList(ChartInfoVo.class);
            FinanceVo financeVo = new FinanceVo();
            FinanceVo financeVo2 = new FinanceVo();
            for (ChartInfoVo chartInfoVo : chartInfoVos) {
                if (chartInfoVo.getType().equals("年报")) {
                    String s = chartInfoVo.getBody();
                    JSONArray jsonArray1 = JSONArray.parseArray(s);
                    int size = jsonArray1.size();
                    JSONArray jsonArray2 = jsonArray1.getJSONArray(size - 1);
                    JSONArray jsonArray3 = jsonArray1.getJSONArray(size - 2);
                    financeVo.setZ_zc(jsonArray2.get(1).toString());
                    financeVo.setZ_fz(jsonArray2.get(2).toString());
                    financeVo2.setZ_fz(jsonArray3.get(2).toString());
                    financeVo2.setZ_zc(jsonArray3.get(1).toString());

                }
            }
            JSONArray listInfoArray = content.getJSONObject("profitSheet").getJSONArray("listInfo");
            List<ChartInfoVo> chartInfoVos1 = listInfoArray.toJavaList(ChartInfoVo.class);
            for (ChartInfoVo chartInfoVo : chartInfoVos1) {
                if (chartInfoVo.getType().equals("年报")) {
                    String s = chartInfoVo.getBody();
                    JSONArray jsonArray1 = JSONArray.parseArray(s);
                    financeVo.setYy_zsr(jsonArray1.getJSONArray(0).get(1).toString());
                    financeVo.setYy_lr(jsonArray1.getJSONArray(2).get(1).toString());
                    financeVo.setJb_mg_sy(jsonArray1.getJSONArray(6).get(1).toString());
                    financeVo.setXs_mg_sy(jsonArray1.getJSONArray(6).get(1).toString());
                }
                if (chartInfoVo.getType().equals("中报")) {
                    String s = chartInfoVo.getBody();
                    JSONArray jsonArray3 = JSONArray.parseArray(s);
                    financeVo2.setYy_zsr(jsonArray3.getJSONArray(0).get(1).toString());
                    financeVo2.setYy_lr(jsonArray3.getJSONArray(2).get(1).toString());
                    financeVo2.setXs_mg_sy(jsonArray3.getJSONArray(6).get(1).toString());
                }
            }
            financeVos.add(financeVo);
            financeVos.add(financeVo2);
//            financeVo.setZ_zc();
        }
        return AjaxResult.success(financeVos);
    }

    /**
     * 公司概况
     */
    //https://datacenter.eastmoney.com/securities/api/data/v1/get?reportName=RPT_F10_BASIC_ORGINFO&columns=ALL&quoteColumns=&filter=(SECUCODE%3D%22300792.SZ%22)&pageNumber=1&pageSize=1&sortTypes=&sortColumns=&source=HSF10&client=PC&v=08281161563709811
    // https://finance.pae.baidu.com/vapi/v1/getquotation?srcid=5353&all=1&code=301399&query=301399&eprop=min&stock_type=ab&chartType=minute&group=quotation_minute_ab&finClientType=pc
    @ApiOperation("公司概况")
    @GetMapping("/company")
    public AjaxResult companyData(@RequestParam(name = "f12", required = true) String f12, @RequestParam(name = "f14") String f14) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://finance.pae.baidu.com/api/stockwidget?code=" + f12 + "&market=ab&type=stock&widgetType=company&finClientType=pc"); //示例URL，请替换为实际的股票代码
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        CompanyDataVo companyDataVo = new CompanyDataVo();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject result1 = JSONObject.parseObject(result).getJSONObject("Result").getJSONObject("content").getJSONObject("newCompany");
            JSONObject basicinfos = result1.getJSONObject("basicInfo");
            companyDataVo = basicinfos.toJavaObject(CompanyDataVo.class);

        }
        StrBuilder strBuilder = new StrBuilder();
        if (!ObjectUtils.isEmpty(companyDataVo) && !companyDataVo.getConcepts().isEmpty()) {
            for (ConceptsCompanyVo concept : companyDataVo.getConcepts()) {
                strBuilder.append(concept.getText()).append(",");
            }
            companyDataVo.setConceptsText(String.valueOf(strBuilder));
        }
        return AjaxResult.success(companyDataVo);
    }

    @ApiOperation("公司板块数据")
    @GetMapping("/sector")
    public AjaxResult sectorData(@RequestParam(name = "f12", required = true) String f12, @RequestParam(name = "f14") String f14) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://finance.pae.baidu.com/api/getrelatedblock?stock=%7B%22market%22:%22ab%22,%22type%22:%22stock%22,%22code%22:%22" + f12 + "%22%7D&finClientType=pc"); //示例URL，请替换为实际的股票代码
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        gGUsectorVo gGUsectorVo = new gGUsectorVo();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject result1 = JSONObject.parseObject(result).getJSONObject("Result");
            JSONArray jsonArray = result1.getJSONArray(f12);
            List<SectorVo> companyDataVos = jsonArray.toJavaList(SectorVo.class);
            for (SectorVo companyDataVo : companyDataVos) {
                if (companyDataVo.getName().equals("地域")) {
                    gGUsectorVo.setDy_list(companyDataVo.getList());
                }
                if (companyDataVo.getName().equals("行业")) {
                    gGUsectorVo.setHy_list(companyDataVo.getList());
                }
                if (companyDataVo.getName().equals("概念")) {
                    gGUsectorVo.setGn_list(companyDataVo.getList());
                }
            }

        }
        return AjaxResult.success(gGUsectorVo);
    }

    //日K

    @ApiOperation("日K数据")
    @GetMapping("/dayKline")
    public AjaxResult getdayKline(@RequestParam(name = "f12", required = true) String f12) throws IOException {
        String secid = null;
        String code = f12; // 替换为你需要的股票代码
        String marketType = getAStockMarket(code);
        if (marketType.equals("沪市A股")) {
            secid = "1." + code;
        } else if (marketType.equals("深市A股")) {
            secid = "0." + code;
        } else {
            secid = "0." + code;
        }
        Date now = new Date();
        // 定义日期格式
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        // 格式化
        String formattedDate = sdf1.format(now);
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=" + secid + "&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=101&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        return getKLine(client, request);
    }

    private boolean findTimeFormat(String input, String pattern) {
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(input);
        return m.find();
    }

    @ApiOperation("周K数据")
    @GetMapping("/weekKline")
    public AjaxResult getweekKline(@RequestParam(name = "f12", required = true) String f12) throws IOException {
        String secid = null;
        String code = f12; // 替换为你需要的股票代码
        String marketType = getAStockMarket(code);
        if (marketType.equals("沪市A股")) {
            secid = "1." + code;
        } else if (marketType.equals("深市A股")) {
            secid = "0." + code;
        } else {
            secid = "0." + code;
        }
        Date now = new Date();
        // 定义日期格式
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        // 格式化
        String formattedDate = sdf1.format(now);
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=" + secid + "&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=102&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        return getKLine(client, request);
    }

    @ApiOperation("月K数据")
    @GetMapping("/monthKline")
    public AjaxResult getmonthKline(@RequestParam(name = "f12", required = true) String f12) throws IOException {
        String secid = null;
        String code = f12; // 替换为你需要的股票代码
        String marketType = getAStockMarket(code);
        if (marketType.equals("沪市A股")) {
            secid = "1." + code;
        } else if (marketType.equals("深市A股")) {
            secid = "0." + code;
        } else {
            secid = "0." + code;
        }
        Date now = new Date();
        // 定义日期格式
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        // 格式化
        String formattedDate = sdf1.format(now);
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=" + secid + "&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=103&fqt=1&beg=20200101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        return getKLine(client, request);
    }

    //
    @ApiOperation("季K数据")
    @GetMapping("/quarterKline")
    public AjaxResult getquarterKline(@RequestParam(name = "f12", required = true) String f12) throws IOException {
        String secid = null;
        String code = f12; // 替换为你需要的股票代码
        String marketType = getAStockMarket(code);
        if (marketType.equals("沪市A股")) {
            secid = "1." + code;
        } else if (marketType.equals("深市A股")) {
            secid = "0." + code;
        } else {
            secid = "0." + code;
        }
        Date now = new Date();
        // 定义日期格式
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        // 格式化
        String formattedDate = sdf1.format(now);
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=" + secid + "&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=104&fqt=1&beg=20000101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        return getKLine(client, request);
    }

    private AjaxResult getKLine(HttpClient client, HttpGet request) throws IOException {
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        MinuteDataVo minuteDataVo = new MinuteDataVo();
        List<Object> data1 = minuteDataVo.getData();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject json = JSON.parseObject(result);
            JSONObject data = json.getJSONObject("data");
            JSONArray klines = data.getJSONArray("klines");
            // 1分钟K线的时间格式通常为 "yyyy-MM-dd HH:mm"
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
            for (int i = 0; i < klines.size(); i++) {
                String k = klines.getString(i);
                String[] arr = k.split(",");
                Object[] row = new Object[arr.length + 1];

                // 处理时间戳
                String dateStr = arr[0]; // 例如 "2025-06-09 09:40"
                long ts = 0;
                try {
                    Date date = sdf.parse(dateStr);
                    ts = date.getTime() / 1000; // 秒级时间戳
                } catch (Exception e) {
                    // 如果格式是"yyyy-MM-dd"，可以用另一个格式处理
                    try {
                        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
                        sdf2.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
                        Date date = sdf2.parse(dateStr);
                        ts = date.getTime() / 1000;
                    } catch (Exception ex) {
                        ts = 0;
                    }
                }

                row[0] = ts;
                row[1] = dateStr;
                // 其余字段转数字
                for (int j = 1; j < arr.length; j++) {
                    try {
                        if (arr[j].contains(".")) {
                            row[j + 1] = Double.parseDouble(arr[j]);
                        } else {
                            row[j + 1] = Integer.parseInt(arr[j]);
                        }
                    } catch (Exception e) {
                        row[j + 1] = arr[j];
                    }
                }
                data1.add(row); // 添加到结果集中
            }
        }
        return AjaxResult.success(minuteDataVo);
    }


    /**
     * 获取上证指数1.000001 表示上证指数，深证指数0.399001 表示深证成指，创业板指数0.399006，沪深300：1.000300，科创50接口1.000688
     */

    @ApiOperation("获取指数详情数据")
    @GetMapping("/getzhiShuData")
    public AjaxResult getzhiShuData(@RequestParam(name = "symbol", required = true) String symbol) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet();
        if (symbol.equals("000001")) {//上证指数
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=1.000001"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399001")) {//深证指数
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=0.399001"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399006")) {//创业板指数
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=0.399006"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000688")) {//科创50
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=1.000688"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000300")) {//沪深300
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=1.000300"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000682")) {//科创信息
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=1.000682"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000683")) {//科创生物
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=1.000683"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000685")) {//科创芯片
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=1.000685"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000687")) {//科创高装
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=1.000687"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000689")) {//科创芯片
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=1.000689"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399673")) {//创业板50
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=0.399673"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399012")) {//创业板300
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=0.399012"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399293")) {//创业板大盘
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=0.399293"); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399102")) {//创业板大盘
            request = new HttpGet("http://push2.eastmoney.com/api/qt/stock/get?secid=0.399102"); //示例URL，请替换为实际的股票代码
        }
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        MlKLineMasterVo mlKLineMasterVo = new MlKLineMasterVo();
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject result1 = JSONObject.parseObject(result).getJSONObject("data");
            //代码
            if (StringUtils.isNotEmpty(result1.getString("f57"))) {
                mlKLineMasterVo.setF12(result1.getString("f57"));
            }
            //名称
            mlKLineMasterVo.setF14(result1.getString("f58"));
            //最新价格
            if (StringUtils.isNotEmpty(result1.getString("f43")) && !result1.getString("f43").equals("0")) {
                mlKLineMasterVo.setF2(String.valueOf(new BigDecimal(result1.getString("f43")).divide(new BigDecimal(100))));
            }
            //最高
            if (StringUtils.isNotEmpty(result1.getString("f44")) && !result1.getString("f44").equals("0")) {
                mlKLineMasterVo.setF15(String.valueOf(new BigDecimal(result1.getString("f44")).divide(new BigDecimal(100))));
            }
            //最低
            if (StringUtils.isNotEmpty(result1.getString("f45")) && !result1.getString("f45").equals("0")) {
                mlKLineMasterVo.setF16(String.valueOf(new BigDecimal(result1.getString("f45")).divide(new BigDecimal(100))));
            }
            //今开价格
            if (StringUtils.isNotEmpty(result1.getString("f46")) && !result1.getString("f46").equals("0")) {
                mlKLineMasterVo.setF17(String.valueOf(new BigDecimal(result1.getString("f46")).divide(new BigDecimal(100))));

            }
            //昨收
            if (StringUtils.isNotEmpty(result1.getString("f60")) && !result1.getString("f60").equals("0")) {
                mlKLineMasterVo.setF18(String.valueOf(new BigDecimal(result1.getString("f60")).divide(new BigDecimal(100))));
            }
            BigDecimal subtract = new BigDecimal(mlKLineMasterVo.getF2()).subtract(new BigDecimal(mlKLineMasterVo.getF18()));
            BigDecimal bigDecimal = new BigDecimal(mlKLineMasterVo.getF2());
            BigDecimal divide = subtract.divide(bigDecimal, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
            mlKLineMasterVo.setF3(String.valueOf(divide));
            mlKLineMasterVo.setF5(result1.getString("f47"));
            //成交额
            if (StringUtils.isNotEmpty(result1.getString("f48")) && !result1.getString("f48").equals("0")) {
                String s = String.valueOf(new BigDecimal(result1.getString("f48")).divide(new BigDecimal(100000000), 2, RoundingMode.HALF_UP));
                mlKLineMasterVo.setF6(s);
            }

        }
        return AjaxResult.success(mlKLineMasterVo);
    }

    /**
     * klt：K线类型（1=1分，5=5分，101=日K，102=周K，103=月K）
     *
     * @param symbol
     * @return
     * @throws IOException
     * @throws ParseException
     */
    @ApiOperation("获取指数详情K线，参数symbol，参数kdata（kdata=1是一分钟K线，5=5分，101=日K，102=周K，103=月K）")
    @GetMapping("/getzhiShuKline")
    public AjaxResult getzhiShuKline(@RequestParam(name = "symbol", required = true) String symbol, @RequestParam(name = "kdata", required = true) String kdata) throws IOException, ParseException {
        HttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet();
        Date now = new Date();
        // 定义日期格式
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        // 格式化
        String formattedDate = sdf1.format(now);
        if (symbol.equals("000001")) {//上证指数
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000001&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399001")) {//深证指数
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=0.399001&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399006")) {//创业板指数
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=0.399006&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000688")) {//科创50
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000688&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000300")) {//沪深300
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000300&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000682")) {//科创信息
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000682&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000683")) {//科创生物
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000683&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000685")) {//科创芯片
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000682&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000687")) {//科创高装
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000687&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("000689")) {//科创芯片
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000689&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399673")) {//创业板50
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=0.399673&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399012")) {//创业板300
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=0.399012&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399293")) {//创业板大盘
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=0.399293&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        } else if (symbol.equals("399102")) {//创业板大盘
            request = new HttpGet("https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=0.399102&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58&klt=" + kdata + "&fqt=1&beg=20220101&end=" + formattedDate); //示例URL，请替换为实际的股票代码
        }
        request.setHeader("Content-Type", "text/javascript;charset=UTF-8");
        HttpResponse response = client.execute(request);
        List<Object> resultList = new ArrayList<>();

        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8").replace("jQuery", "");
            JSONObject json = JSON.parseObject(result);
            JSONObject data = json.getJSONObject("data");
            JSONArray klines = data.getJSONArray("klines");

            // 1分钟K线的时间格式通常为 "yyyy-MM-dd HH:mm"
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
            for (int i = 0; i < klines.size(); i++) {
                String k = klines.getString(i);
                String[] arr = k.split(",");
                Object[] row = new Object[arr.length + 1];

                // 处理时间戳
                String dateStr = arr[0]; // 例如 "2025-06-09 09:40"
                long ts = 0;
                try {
                    Date date = sdf.parse(dateStr);
                    ts = date.getTime() / 1000; // 秒级时间戳
                } catch (Exception e) {
                    // 如果格式是"yyyy-MM-dd"，可以用另一个格式处理
                    try {
                        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
                        sdf2.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
                        Date date = sdf2.parse(dateStr);
                        ts = date.getTime() / 1000;
                    } catch (Exception ex) {
                        ts = 0;
                    }
                }

                row[0] = ts;
                row[1] = dateStr;
                // 其余字段转数字
                for (int j = 1; j < arr.length; j++) {
                    try {
                        if (arr[j].contains(".")) {
                            row[j + 1] = Double.parseDouble(arr[j]);
                        } else {
                            row[j + 1] = Integer.parseInt(arr[j]);
                        }
                    } catch (Exception e) {
                        row[j + 1] = arr[j];
                    }
                }
                resultList.add(row); // 添加到结果集中
            }

        }
        return AjaxResult.success(resultList);
    }

    /**
     * 获取指数下面股票
     *
     * @param symbol
     * @return
     * @throws IOException
     * @throws ParseException
     */

    @ApiOperation("获取指数股票symbol指数代码，sort，排序方式，1涨幅，2跌幅,market=0代表涨跌幅榜单，1市值榜单")
    @GetMapping("/getzhiShuSymbolData")
    public AjaxResult getzhiShuSymbolData(@RequestParam(name = "symbol", required = true) String symbol, @RequestParam(name = "sort", required = true) String sort, @RequestParam(name = "market") String market) throws IOException, ParseException {
        HttpClient client = HttpClients.createDefault();
        List<MlKLineMasterVo> mlKLineMasterVos = new ArrayList<>();
        if (sort.equals("1")) {
            sort = String.valueOf(0);
        } else if (sort.equals("2")) {
            sort = String.valueOf(1);
        }
        if (market.equals("0")) {
            market = "changepercent";
        } else if (market.equals("1")) {
            market = "marketcapital";
        }
        if (symbol.equals("000001")) {//上证指数
            /**
             * 沪深京涨幅
             */
            HttpGet request3 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=30&sort=" + market + "&asc=" + sort + "&node=hs_a"); //示例URL，请替换为实际的股票代码
            HttpResponse response3 = client.execute(request3);
            mlKLineMasterVos = mlKLineMasters(request3, response3);
        } else if (symbol.equals("399001")) {
            /**
             * 沪深京涨幅
             */
            HttpGet request3 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=30&sort=" + market + "&asc=" + sort + "&node=hs_a"); //示例URL，请替换为实际的股票代码
            HttpResponse response3 = client.execute(request3);
            mlKLineMasterVos = mlKLineMasters(request3, response3);
        } else if (symbol.equals("399006") || symbol.equals("399673") || symbol.equals("399012") || symbol.equals("399293") || symbol.equals("399102")) {//创业板指数
            /**
             *  创业板涨幅
             */
            HttpGet request = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=20&sort=" + market + "&asc=" + sort + "&node=cyb"); //示例URL，请替换为实际的股票代码
            HttpResponse response = client.execute(request);
            mlKLineMasterVos = mlKLineMasters(request, response);
        } else if (symbol.equals("000300")) {//沪深300
            /**
             * 沪深京涨幅
             */
            HttpGet request3 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=30&sort=" + market + "&asc=" + sort + "&node=hs_a"); //示例URL，请替换为实际的股票代码
            HttpResponse response3 = client.execute(request3);
            mlKLineMasterVos = mlKLineMasters(request3, response3);
        } else if (symbol.equals("000682") || symbol.equals("000685") || symbol.equals("000687") || symbol.equals("000683")) {//科创信息
            /**
             * 科创板涨幅
             */
            HttpGet request5 = new HttpGet("http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=20&sort=" + market + "&asc=" + sort + "&node=kcb"); //示例URL，请替换为实际的股票代码
            HttpResponse response5 = client.execute(request5);
            mlKLineMasterVos = mlKLineMasters(request5, response5);
        }
        return AjaxResult.success(mlKLineMasterVos);

    }
}


